#include "PlayerHard.h"
#include "PlayerGift.h"
#include "Chat.h"
#include "Common.h"
#include "Unit.h"
#include "Config.h"
#include "Player.h"
#include "ScriptMgr.h"
#include "World.h"
#include "WorldSession.h"
#include "WorldSessionMgr.h"


void PlayerHardScript::OnPlayerJustDied(Player* player) {
    PlayerSetting ps = player->GetPlayerSetting(KKK_GIFT_SOURCE, KKK_GIFT_HARD_MODE_INX);
    if (ps.HasFlag(KKK_GIFT_HARD_MODE_ENABLE) ){
        uint32 value = ps.value | KKK_GIFT_HARD_MODE_STATUS;
        ps.AddFlag(KKK_GIFT_HARD_MODE_STATUS);
        player->UpdatePlayerSetting(KKK_GIFT_SOURCE,KKK_GIFT_HARD_MODE_INX,value);
        ChatHandler(player->GetSession()).PSendSysMessage("江湖再见。。。英雄，请重新来过！！！(释放灵魂后，将断开连接，请重新登录！)");
        ChatHandler(player->GetSession()).PSendSysMessage("江湖再见。。。英雄，请重新来过！！！(释放灵魂后，将断开连接，请重新登录！)");
        ChatHandler(player->GetSession()).PSendSysMessage("江湖再见。。。英雄，请重新来过！！！(释放灵魂后，将断开连接，请重新登录！)");
        ChatHandler(player->GetSession()).PSendSysMessage("江湖再见。。。英雄，请重新来过！！！(释放灵魂后，将断开连接，请重新登录！)");
        ChatHandler(player->GetSession()).PSendSysMessage("江湖再见。。。英雄，请重新来过！！！(释放灵魂后，将断开连接，请重新登录！)");

        string name = player->GetName();
        sWorldSessionMgr->SendServerMessage(SERVER_MSG_STRING,"江湖再见 >>>>" + name + "<<<<  一位英雄倒下了。" );
    }else{
        //ChatHandler(player->GetSession()).PSendSysMessage("普通模式，挂了！！！");
    }
}

void PlayerHardScript::OnPlayerLogin(Player* player){
    PlayerSetting ps = player->GetPlayerSetting(KKK_GIFT_SOURCE, KKK_GIFT_HARD_MODE_INX);
    if (ps.HasFlag(KKK_GIFT_HARD_MODE_ENABLE) && ps.HasFlag(KKK_GIFT_HARD_MODE_STATUS) ){
        ChatHandler(player->GetSession()).PSendSysMessage("江湖再见。。。英雄，请重新来过！！！");
        player->RemoveFromWorld();
    }
    if (ps.HasFlag(KKK_GIFT_HARD_MODE_ENABLE) && !ps.HasFlag(KKK_GIFT_HARD_MODE_STATUS) ){ 
        ChatHandler(player->GetSession()).PSendSysMessage("***************************************");
        ChatHandler(player->GetSession()).PSendSysMessage("英雄，当前处于一命模式, 请珍惜生命！！！");
        ChatHandler(player->GetSession()).PSendSysMessage("英雄，当前处于一命模式, 请珍惜生命！！！");
        ChatHandler(player->GetSession()).PSendSysMessage("英雄，当前处于一命模式, 请珍惜生命！！！");
        ChatHandler(player->GetSession()).PSendSysMessage("英雄，当前处于一命模式, 请珍惜生命！！！");
        ChatHandler(player->GetSession()).PSendSysMessage("***************************************");
    }
}

void PlayerHardScript::OnPlayerReleasedGhost(Player* player){
    PlayerSetting ps = player->GetPlayerSetting(KKK_GIFT_SOURCE, KKK_GIFT_HARD_MODE_INX);
    if (ps.HasFlag(KKK_GIFT_HARD_MODE_ENABLE) && ps.HasFlag(KKK_GIFT_HARD_MODE_STATUS) ){
        ChatHandler(player->GetSession()).PSendSysMessage("江湖再见。。。英雄，请重新来过！！！");
        player->RemoveFromWorld();
    }else{
        //ChatHandler(player->GetSession()).PSendSysMessage("普通模式，释放了！！！");
    }
    
}

void PlayerHardScript::OnPlayerResurrect(Player* player, float restore_percent, bool applySickness){
    PlayerSetting ps = player->GetPlayerSetting(KKK_GIFT_SOURCE, KKK_GIFT_HARD_MODE_INX);
    if (ps.HasFlag(KKK_GIFT_HARD_MODE_ENABLE) && ps.HasFlag(KKK_GIFT_HARD_MODE_STATUS) ){
        ChatHandler(player->GetSession()).PSendSysMessage("江湖再见。。。英雄，请重新来过！！！");
        player->RemoveFromWorld();
    }else{
       // ChatHandler(player->GetSession()).PSendSysMessage("普通模式，复活了！！！");
    }
}

// Add all scripts in one
void hardScripts()
{
    new PlayerHardScript();
}
